var express = require('express');
var router = express.Router();

/* GET home page. */
router.post('/login', function(req, res, next) {
    let loginData = req.body;
    console.log(loginData.username)
    console.log(loginData.password)
    var data = { token: 'tokenStr.tokenStr.tokenStr' };
    res.send(new ResponseResult().ok(data));
});

router.get('/menus', function(req, res, next) {
    let authorization = req.headers.Authorization
    console.log(authorization)
    var data = [];
    data[0] = {
        id: 101,
        order: 1,
        path: 'users',
        authName: '用户管理',
        children: [{
            id: 10101,
            order: 1,
            path: 'users',
            authName: '用户列表',
            children: []
        }, {
            id: 10102,
            order: 2,
            path: 'users',
            authName: '黑名单',
            children: []
        }]
    }
    data[1] = {
        id: 102,
        order: 2,
        path: 'orders',
        authName: '订单管理',
        children: [{
            id: 10201,
            order: 1,
            path: 'orders',
            authName: '订单列表',
            children: []
        }, {
            id: 10202,
            order: 2,
            path: 'orders',
            authName: '售后管理',
            children: []
        }]
    }
    res.send(new ResponseResult().ok(data));
})

module.exports = router;

class ResponseResult {
    constructor() {
        this.code = 2000;
        this.msg = 'OK';
        this.isSuccess = true;
        this.data = '';
    }
    ok(data) {
        this.data = data;
        return this;
    }
}